package leetcode.easy;

/**
 * ClassName: $680_ValidPalindromeII
 * Description:
 * date: 2021-10-22 23:52
 *
 * @author liyifan
 */
public class $680_ValidPalindromeII {
    public boolean validPalindrome(String s) {
        int left = 0;
        int right = s.length() - 1;
        while (left < right) {
            if (s.charAt(left) == s.charAt(right)){
                left++;
                right--;
            } else {
                return help(s, left + 1, right) || help(s, left, right - 1);
            }
        }
        return true;
    }

    public boolean help(String s, int left, int right) {
        for (int i = left,  j = right;i <= j;i++, j--) {
            if (s.charAt(i) != s.charAt(j))
                return false;
        }
        return true;
    }
}
